package edu.whu.webgis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import edu.whu.webgis.entity.Message;
import edu.whu.webgis.mapper.MessageMapper;
import edu.whu.webgis.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements IMessageService {

    @Autowired
    MessageMapper mapper;

    @Override
    public void sendMessage(Message message) {
        mapper.insert(message);
    }

    @Override
    public List<Message> selectMessageLimit(Integer id, Integer limit) {
        LambdaQueryWrapper<Message> qw = new LambdaQueryWrapper<>();
        qw.gt(Message::getId, id)
        .orderByDesc(Message::getId)
        .last("limit " + limit);
        return mapper.selectList(qw);
    }

    @Override
    public List<Message> selectHistoryMessage(Integer id, Integer limit) {
        LambdaQueryWrapper<Message> qw = new LambdaQueryWrapper<>();
        qw.lt(Message::getId, id)
                .orderByDesc(Message::getId)
                .last("limit " + limit);
        return mapper.selectList(qw);
    }
}
